<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">机构用户管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>知识库应用管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">机构用户管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">


		<div class="row mbl">
			<div class="col-lg-6">
				<div class="input-group input-group-sm mbs">
					<span class="input-group-btn"> <select id="queryParams"
						data-toggle="dropdown" class="btn btn-danger dropdown-toggle"
						style="width :100px;">
							<!-- <option value="-1">
								筛选项&nbsp;<span class="caret"></span>
							</option> -->
							<option value="username">用户名</option>
							<option value="realname">机构名称</option>
					</select> </span> <input id="text" type="text" placeholder="请输入关键词..."
						class="form-control" /><span class="input-group-btn"><button
							type="button" data-toggle="dropdown"
							class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
					</span>
					
				</div>
			</div>


			<div class="col-lg-6">

				<div class="tb-group-actions pull-right">
					<button class="btn btn-sm btn-primary" onclick="addUpdateUser('0')">新增</button>
					<button class="btn btn-sm btn-primary"
						onclick="organizationUserSearch('0')">机构下用户搜索</button>
					<button class="btn btn-sm btn-primary" onclick="addUserBatch('1')">批量导入机构用户</button>
					<button class="btn btn-sm btn-primary" onclick="modelDownload()">模板下载</button>
					<button class="btn btn-sm btn-primary" onclick="delAll()">删除选中</button>
				</div>
			</div>

		</div>
		<div style="float: right;line-height: 20px; margin-bottom: 10px;"><span id="mcount"></span></div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th><input type="checkbox" onclick="selectAll(this)" class="checkall" name="oncheckall" /></th>
					<th>序号</th>
					<th>用户名</th>
					<th>机构名称</th>
					<th>登录方式</th>
					<th>创建时间</th>
					<th>状态</th>
					<th>可操作</th>
				</tr>
			</thead>
			<tbody id="findMemeber">
			</tbody>
		</table>
		<div id="dataNull" class="panel-body"
			style="height: 90px; line-height: 50px;" align="center"></div>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>

	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var curr;
	var id;
	var userType;
	$(function() {

		demo1(1);
	});
	function get() {
		demo1(curr);
	}
	function getlay() {
		return id;
	}
	function getUserType() {
		return userType;
	}
	function getindex() {
		return '';
	}
	function selectUser(lid) {
		id = lid;
		layer.open({
			type : 2,
			area : [ '800px', '650px' ],
			scrollbar : false,
			shadeClose : true,
			zIndex : layer.zIndex,
			fix : false, //不固定
			title : '机构用户管理',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '关闭' ],
			content : [ "application_organization_select.html?winName="
							+ window.name, 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}

		});
	}
	//机构下用户搜索
	function organizationUserSearch(lid) {
		id = lid;
		layer.open({
			type : 2,
			area : [ '800px', '610px' ],
			scrollbar : false,
			shadeClose : true,
			fix : false, //不固定
			title : '机构下用户管理',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			//btn : [ '关闭' ],
			content : [ "application_organization_user_search.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
			},
			cancel : function(index) {
			}

		});
	}
		function UpdateUser(lid) {
		id = lid;
		layer.open({
			type : 2,
			area : [ '800px', '650px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,

			title : '机构用户管理',
			//maxmin : true,  
			move : true,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "application_organization_add_update.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
			},
			cancel : function(index) {
			}

		});
	}
	function addUpdateUser(lid) {
		id = lid;
		layer.open({
			type : 2,
			area : [ '800px', '650px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,

			title : '机构用户管理',
			//maxmin : true,  
			move : true,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "application_organization_add_update.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
			},
			cancel : function(index) {
			}

		});
	}
	function manage(lid) {
		id = lid;
		layer.open({
			type : 2,
			icon : 1,
			title : "机构下用户管理",
			skin : 'layer-ext-moon',
			area : [ '800px', '600px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			skin : 'layui-layer-rim', //加上边框
			//btn : [ '关闭' ],
			content : [ "application_organization_user_list.html", 'no' ],
			yes : function(index, layer) {
				//  var iframeWin = parent.window[layer.find('iframe')[0]['name']];

			},
			cancel : function(index) {
			}
		});
	}
	/*机构修改密码*/
	function managePassword(lid){
		id = lid;
		layer.open({
			type : 2,
			area : [ '500px', '400px' ],
		    scrollbar: false,
		    shadeClose: true,
			fix : true, //不固定
			title : '修改密码',
			//maxmin : true,  
			skin: 'layui-layer-rim', //加上边框
    	    btn: ['保存 ', '关闭'],
			content : ["application_organization_update_password.html",'no'],
			yes: function(index,layer){
	                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                 iframeWin.UpdatePassword();
	         },
			cancel : function(index) {
			}
			
		});
	}
	function del(id) {
		if (confirm("是否确认删除！！")) {
			$.ajax({
				type : "post",
				url : "./listdel.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data[0] == 'yes'){
						demo1();
						layer.msg('删除成功');
					}else{
						demo1();
						layer.msg('删除失败！请先解除订购或订单关联！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	function demo1(curr) {
		$.getJSON(
						"payOrgAll.do",
						{
							page : curr || 1,
							queryParams : $("#queryParams").val(),
							text : $("#text").val(),
							type : 1
						},
						function(res) {
							//此处仅仅是为了演示变化的内容
							$("#mcount").html("机构下用户共："+res.mcount+"个");
							var str = "";
							$("#findMemeber").html("");
							if (res.listsize > 0) {
								$("#dataNull").html("");
							} else {
								$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
							}
							for ( var i = 0; i < res.listsize; i++) {
								var statusname;
								if (res.result[i].status == 0) {
									statusname = "启用";
								} else {
									statusname = "禁用";
								}
								var loginMode;
								if (res.result[i].loginMode == 0) {
									loginMode = "用户名和密码";
								} else {
									loginMode = "ip自动登录";
								}
									str += "<tr><td>"
										+"<input name='checkall'  type='checkbox' value='"+res.result[i].id+"'/>"
										+"</td><td>"
										+ (i + 1)
										+ "</td><td> <label id=>"
										+ res.result[i].username
										+ "</label></td><td><label >"
										+ res.result[i].realname
										+ "</label></td><td><label >"
										+ loginMode
										+ "</label></td><td><label >"
										+ res.result[i].createTime
										+ "</label></td><td><label >"
										+ statusname
										+ "</label></td><td>"
										+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"UpdateUser('"
										+ res.result[i].id
										+ "')\">"
										+ "更新"
										+ "</button>&nbsp;"
										+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"del('"
										+ res.result[i].id
										+ "')\">"
										+ "删除"
										+ "</button>&nbsp;"
										+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"selectUser('"
										+ res.result[i].id
										+ "')\">"
										+ "查看详情"
										+ "</button>&nbsp;"
										+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"manage('"
										+ res.result[i].id + "')\">"
										+ "机构下用户管理" + "</button>&nbsp;"
										+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"managePassword('"
										+ res.result[i].id + "')\">"
										+ "修改密码" + "</button>"
										+ "</td></tr>";
							}
							$("#findMemeber").append(str);

 							laypage({
								cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
								pages : res.pageSize, //总页数
								skip : true, //是否开启跳页
								skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
								curr : curr || 1,
								last: res.pageSize,
								groups : 6,//连续显示分页数
								jump : function(obj, first) { //触发分页后的回调
									if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
										demo1(obj.curr);
										var curr = obj.curr;
										curr = obj.curr;
									}
								}
							}); 
						/* layui.use(['laypage'], function(){
							var laypage = layui.laypage;
							 laypage.render({
							    elem: 'page2' //分页容器的id
							    ,count: res.pageSize
							    ,skin: '#1E9FFF' //自定义选中色值
							    ,curr : curr || 1
							    ,layout: ['prev', 'page', 'next', 'skip', 'count']
							    ,jump: function(obj, first){
							      if(!first){
							        demo1(obj.curr);
							        var curr = obj.curr;
									curr = obj.curr;						        
							      }
							    }
							  });
							}); */
							
						});
	};
	//批量导入机构用户
	function addUserBatch(type) {
		userType = type;
		layer.open({
			type : 2,
			area : [ '500px', '350px' ],
		    scrollbar: false,
		    shadeClose: true,
			fix : true, //不固定
			title : '机构用户批量导入',
			//maxmin : true,  
			skin: 'layui-layer-rim', //加上边框
    	    btn: ['开始导入','关闭'],
			content : ["application-user-add-batch.html?userType="
							+ type,'no'],
			yes: function(index,layer){
	                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                 iframeWin.applicationUserAddBach();
	         },
			cancel : function(index) {
			}
			
		});
	}
	function delAll() {
		if (confirm("是否确认选中删除！！")){
			var valueIds=[];
				$("input[name='checkall']:checked").each(function(){
					valueIds.push($(this).val());
				}); 
			$.ajax({
				type : "post",
				url : "./memberDelAll.do",
				data : {
					"valueIds" : valueIds
				},
				dataType : "json",
				traditional : true,
				success : function(data) {
					if(data[0] == 'yes'){
						demo1(curr);
						layer.msg('删除成功');
					}else{
						demo1(curr);
						layer.msg('删除失败！请先解除订购或订单关联！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	} 
	//下载用户导入模板
	function modelDownload(){
		var url="./userAddBatchModelDownload.do";
		window.location.href=url;
	}
</script>